<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            width: 220px;
            height: 50px;
            margin: 20px auto;
            border: 1px solid #ccc;
            position: relative;
            overflow: hidden;
        }

        .icon {
            width: 100%;
            height: 50px;
            position: absolute;
        }

        .icon:nth-child(1) {
            background-color: #f00;
            top: 0;
            left: 100%;
        }

        .icon:nth-child(2) {
            background-color: #0f0;
            top: 0;
            left: 0;
        }

        img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="icon childM1">
            <img src="./1.svg" alt="">
        </div>
        <div class="icon childM2">
            <img src="./2.svg" alt="">
        </div>
    </div>


    <script>
        var childM1 = document.querySelector('.childM1');
        var childM2 = document.querySelector('.childM2');
        childM1.onclick = function () {
            console.log('childM1');
            childM1.style.left = '100%';
            childM2.style.left = '0';
            childM1.style.transition = 'left 0.5s';
            childM2.style.transition = 'left 0.5s';
        }

        childM2.onclick = function () {
            console.log('childM2');
            childM1.style.left = '0%';
            childM2.style.left = '100%';
            childM1.style.transition = 'left 0.5s';
            childM2.style.transition = 'left 0.5s';
        }
    </script>
</body>

</html>